package cc.mrbird.febs.power.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.power.entity.BlacklistInfo;
import cc.mrbird.febs.power.service.IBlacklistInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MrBird
 */
@RestController
@RequestMapping("/power/blacklist-info")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BlacklistInfoController {

    private final IBlacklistInfoService iBlacklistInfoService;

    /**
     * 分页获取黑名单
     * @param page
     * @param blacklistInfo
     * @return
     */
    @GetMapping("/page")
    public R getBlacklistInfoByPage(Page page,BlacklistInfo blacklistInfo) {
        return R.ok(iBlacklistInfoService.page(page, Wrappers.<BlacklistInfo>lambdaQuery()));
    }

    /**
     * 新增黑名单
     * @param blacklistInfo
     * @return
     */
    @PostMapping("/BlacklistInfoAdd")
    public R BlacklistInfoAdd(BlacklistInfo blacklistInfo) {
        return R.ok(iBlacklistInfoService.save(blacklistInfo));
    }

    /**
     * 修改黑名单
     * @param blacklistInfo
     * @return
     */
    @PutMapping("/BlacklistInfoEdit")
    public R BlacklistInfoEdit(BlacklistInfo blacklistInfo) {
        return R.ok(iBlacklistInfoService.updateById(blacklistInfo));
    }

    /**
     * 根据ID删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R BlacklistInfoDel(@PathVariable Integer id) {
        return R.ok(iBlacklistInfoService.removeById(id));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/man/ids")
    public R BlacklistInfoSDel(@RequestBody List<Integer> ids) {
        return R.ok(iBlacklistInfoService.removeByIds(ids));
    }

}
